package com.mjlf.thread;

import java.util.List;

/**
 * @ClassName TestThread
 * @Author mjlft
 * @Date 2019/7/6 16:22
 * @Version 1.0
 * @Description TODO
 */
public class TestThread {

    int i = 10;

    public synchronized void  test(){
        while (i -- > 5){
            System.out.println(Thread.currentThread().getName());

            try {
                Thread.currentThread().sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        TestThread t1 = new TestThread();
        TestThread t2 = new TestThread();
        new Thread(()->{
            t1.test();
        }).start();
        new Thread(()->{
            t1.test();
        }).start();


        try {
            Thread.currentThread().sleep(100000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
